// This file is part of OpenMeca, an easy software to do mechanical simulation.
//
// Author(s)    :  - Damien ANDRE  <openmeca@gmail.com>
//
// Copyright (C) 2012 Damien ANDRE
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.


#ifndef OpenMeca_Item_PartUserPipe_hpp
#define OpenMeca_Item_PartUserPipe_hpp


#include "OpenMeca/Item/PartUser.hpp"
#include "OpenMeca/Core/AutoRegisteredPtr.hpp"
#include "OpenMeca/Core/AutoRegister.hpp"
#include "OpenMeca/Gui/UserItemDialogPartUserPipe.hpp"
#include "OpenMeca/Item/PartUserPoint.hpp"

namespace OpenMeca
{  

  namespace Item
  {

    class PartUserPipe: public PartUser, public Core::AutoRegister<PartUserPipe> 
    {
    
    public:
      static const std::string GetStrType(); 
      static void Init();
      static void DrawIcon(QIcon&, QColor);
      typedef Gui::UserItemDialogPartUserPipe Dialog;


    public:
      PartUserPipe(PartUserPoint& point);
      virtual ~PartUserPipe();
      void DrawShape();
      void UpdateIcon();
      void BeginDraw();

      Geom::Vector<_3D>& GetAxis();
      double& GetLength();
      
      const Geom::Frame<_3D>& GetReferenceFrame() const;


      PartUserPoint& GetStartPoint();
      const PartUserPoint& GetStartPoint() const ;

    private:
      PartUserPipe(); //Not allowed, just for serialization
      PartUserPipe(const PartUserPipe&);             //Not Allowed
      PartUserPipe& operator=(const PartUserPipe&);  //Not Allowed


      friend class boost::serialization::access;
      template<class Archive>
      void serialize(Archive& ar, const unsigned int);

    private:
      PartUserPoint& startPoint_;
      Geom::Vector<_3D> axis_;
      double length_;
    };

    
    template<class Archive>
    void PartUserPipe::serialize(Archive& ar, const unsigned int)
    {
      ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(PartUser);
      ar & BOOST_SERIALIZATION_NVP(axis_);
      ar & BOOST_SERIALIZATION_NVP(length_);
    }
    



  }

}


namespace boost 
{ 
  namespace serialization 
  {
    template<class Archive>
    inline void save_construct_data(Archive & ar, 
				    const OpenMeca::Item::PartUserPipe * t, 
				    const unsigned int)
    {
      const OpenMeca::Item::PartUserPoint* parent = &t->GetStartPoint();
      ar << parent;
    }
    
    template<class Archive>
    inline void load_construct_data(Archive & ar, 
				    OpenMeca::Item::PartUserPipe * t, 
				    const unsigned int)
    {
      OpenMeca::Item::PartUserPoint* parent = 0;
      ar >> parent;
      ::new(t)OpenMeca::Item::PartUserPipe(*parent);
    }
  }
} // namespace ...

#endif
